/* GUI CONVERTED from reshmtb.p (converter v1.76) Thu Jul 18 21:54:32 2002 */
/* reshmtb.p - REPETITIVE   SUBCONTRACT SHIPPER MAINT SUBPROGRAM              */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.7.3.9 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 11/09/94   BY: WUG *GO39*                */
/* REVISION: 7.3      LAST MODIFIED: 02/28/95   BY: WUG *G0G2*                */
/* REVISION: 8.5      LAST MODIFIED: 05/12/95   BY: pma *J04T*                */
/* REVISION: 7.3      LAST MODIFIED: 06/15/95   BY: STR *G0N9*                */
/* REVISION: 8.5      LAST MODIFIED: 07/24/95   BY: tjs *J060*                */
/* REVISION: 7.2      LAST MODIFIED: 08/17/95   BY: qzl *F0TC*                */
/* REVISION: 8.6      LAST MODIFIED: 04/09/97   BY: *K08N* Steve Goeke        */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 07/17/00   BY: *M0PQ* Falguni Dalal      */
/* REVISION: 9.1      LAST MODIFIED: 08/02/00   BY: *N0GD* Ganga Subramanian  */
/* REVISION: 9.1      LAST MODIFIED: 09/14/00   BY: *L13V* Vandna Rohira      */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.7.3.7    BY: Jean Miller        DATE: 05/15/02  ECO: *P05V*  */
/* $Revision: 1.7.3.9 $   BY: Ashish Maheshwari  DATE: 07/17/02  ECO: *N1GJ*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*! Maintain list of contained items */

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input parameter abs_recid as recid.
define input parameter consign_issue like mfc_logical.

define new shared variable multi_entry like mfc_logical no-undo
   label "Multi Entry".
define new shared variable cline as character.
define new shared variable lotserial_control like pt_lot_ser.

define new shared variable issue_or_receipt as character.
define new shared variable total_lotserial_qty like sr_qty.
define new shared variable site like sr_site no-undo.
define new shared variable location like sr_loc no-undo.
define new shared variable lotserial like sr_lotser no-undo.
define new shared variable lotserial_qty like sr_qty no-undo.
define new shared variable trans_um like pt_um.
define new shared variable trans_conv like sod_um_conv.
define new shared variable transtype as character initial "ISS-WO".
define new shared variable lotref like sr_ref no-undo.
define new shared variable loc like pt_loc.
define new shared variable change_db like mfc_logical.
define new shared variable ship_site like sod_site.
define new shared variable ship_so like so_nbr.
define new shared variable ship_line like sod_line.
define new shared variable global_order as character.
define new shared variable sod_recno as recid.
define new shared variable global_op as integer.
define new shared variable lotnext like wo_lot_next .
define new shared variable lotprcpt like wo_lot_rcpt no-undo.
define new shared variable undo-all like mfc_logical no-undo.
define new shared variable cmtindx like cmt_indx.

define shared variable h_wiplottrace_procs as handle no-undo.
define shared variable h_wiplottrace_funcs as handle no-undo.

define variable deassign like mfc_logical.
define variable del-yn like mfc_logical.
define variable i as integer.
define variable sr_item like pt_part.
define variable sr_po_nbr like sod_contr_id format "x(22)".
define variable ship_db as character.
define variable qad_wkfl_id as character.
define variable shipto_id as character.
define variable so_db as character.
define variable new_mfguser as character.
define variable default_site like si_site.
define variable scheduled_orders_exist like mfc_logical.
define variable wolot like wo_lot.
define variable op like wr_op.
define variable part like pt_part.
define variable default_loc as character.
define variable operation_wip_mtl as logical.
define variable yn like mfc_logical.
define variable msg_ct as integer.
define variable qty_bkfl as decimal.
define variable input_que_op_to_ck as integer.
define variable input_que_qty_chg as decimal.
define variable access_ok as integer.
define variable v_par_recid  as   recid       no-undo.
define variable v_qty        like sr_qty      no-undo.
define variable v_cmtindx    like abs_cmtindx no-undo.
define variable v_cmmts      like mfc_logical label "Comments" no-undo.
define variable l_trans_conv like sod_um_conv no-undo.
define variable undo_all     like mfc_logical no-undo.

define buffer b_abs_mstr for abs_mstr.
define buffer abs_mstr_item for abs_mstr.
define buffer prev_wr_route for wr_route.


{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i}


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
wolot                colon 20
   op                   colon 51
   part                 colon 20
   pt_desc1             at 42 no-label
   skip(1)
   sr_qty               colon 20
   trans_um
   trans_conv           colon 51 label "Conv"
   sr_site              colon 20
   sr_loc               colon 20
   sr_lotser            colon 20
   sr_ref               colon 20
   multi_entry          colon 20
   v_cmmts              colon 51
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space
 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = (getFrameTitle("CONTENTS_(ITEMS)",24)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/*THE FOLLOWING ENSURES UNIQUE USERID AMONGST MULTIDATABASES*/
/* STD CHECKER ERROR REASSIGNING MFGUSER SO CREATE VARIABLE */
/* NEW_MFGUSER AND USE IN PLACE OF MFGUSER                  */
new_mfguser = mfguser + global_db.

qad_wkfl_id = new_mfguser + "reshmtb.p".
issue_or_receipt = getTermLabel("ISSUE",8).

find first clc_ctrl no-lock no-error.
if not available clc_ctrl then do:
   {gprun.i ""gpclccrt.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   find first clc_ctrl no-lock no-error.
end.

find abs_mstr where recid(abs_mstr) = abs_recid no-lock.

assign
   trans_um = abs__qad02
   trans_conv = decimal(abs__qad03)
   ship_site = abs_shipfrom.

find ad_mstr where ad_addr = abs_shipto no-lock.
shipto_id = ad_addr.

repeat for abs_mstr_item:
/*GUI*/ if global-beam-me-up then undo, leave.


   for each qad_wkfl exclusive-lock
      where qad_key1 = new_mfguser + "reshmtb.p":
      delete qad_wkfl.
   end.

   if is_wiplottrace_enabled() then do:
      run init_move_wip_lot_temptable in h_wiplottrace_procs.
   end.

   for each abs_mstr_item no-lock
      where abs_shipfrom = abs_mstr.abs_shipfrom
        and abs_par_id = abs_mstr.abs_id
        and abs_id begins "i"
   break by abs_order by abs_line by abs_item:

      if first-of(abs_item) then do:
         create qad_wkfl.
         assign
            qad_key1 = qad_wkfl_id
            qad_key2 = string(abs_item,"x(18)") +
                       string(abs_order,"x(8)") +
                       string(integer(abs_line),"9999")
            qad_key3 = qad_wkfl_id
            qad_key4 = string(abs_order,"x(8)") +
                       string(integer(abs_line),"9999") +
                       string(abs_item,"x(18)")
            qad_charfld[1] = abs_item
            qad_charfld[3] = abs_order
            qad_decfld[1] = integer(abs_line).
      end.

   end.

   prompt-for
      wolot
      op
      part
   with frame a
   editing:

      assign
         global_site = ship_site
         global_addr = shipto_id
         global_part = input part
         global_lot = input wolot
         global_order = input wolot
         global_op = integer(input op).

      if frame-field = "part" then do:
         {mfnp05.i qad_wkfl qad_index1
            "qad_key1 = qad_wkfl_id"
            qad_key2 "input part"}
      end.

      else
      if frame-field = "wolot" then do:
         {mfnp05.i qad_wkfl qad_index2
            "qad_key3 = qad_wkfl_id"
            qad_key4 "input wolot"}
      end.

      else
      if frame-field = "op" then do:
         {mfnp05.i qad_wkfl qad_index2
            "qad_key3 = qad_wkfl_id and qad_key4 begins input wolot"
            qad_key4
            "string(input wolot,""x(8)"") + string(input op,"">>>9"")"}
      end.

      else do:
         status input.
         readkey.
         apply lastkey.
      end.

      if recno <> ? then do:

         find pt_mstr where pt_part = qad_charfld[1]
         no-lock no-error.

         display
            pt_part  when (available pt_mstr) @ part
            pt_desc1 when (available pt_mstr)
            ""       when (not available pt_mstr) @ part
            ""       when (not available pt_mstr) @ pt_desc1
            qad_charfld[3] @ wolot
            qad_decfld[1] format ">>>9" @ op
         with frame a.

      end.

   end.

   assign wolot op part.

   /*GET WORKORDER*/
   find wo_mstr where wo_lot = wolot
   no-lock no-error.

   if not available wo_mstr then do:
      /* Work Order/ID does not exist */
      {pxmsg.i &MSGNUM=510 &ERRORLEVEL=3}
      next-prompt wolot.
      undo, retry.
   end.

   if wo_type <> "" and wo_type <> "c" then do:
      /* Invalid Order Type */
      {pxmsg.i &MSGNUM=5103 &ERRORLEVEL=3 &MSGARG1=wo_type}
      next-prompt wolot.
      undo, retry.
   end.

   if wo_site <> abs_mstr.abs_shipfrom then do:
      /* Invalid Order Ship From Site */
      {pxmsg.i &MSGNUM=8228 &ERRORLEVEL=3 &MSGARG1=site}
      undo, retry.
   end.

   if wo_status <> "r" then do:
      /* Work order is closed, plan or firm planned */
      {pxmsg.i &MSGNUM=523 &ERRORLEVEL=3}
      undo, retry.
   end.

   if wo_type = "c" and wo_due_date < today then do:
      /* Cum order has expired */
      {pxmsg.i &MSGNUM=5124 &ERRORLEVEL=2}
   end.

   /*GET WO ROUTING RECORD*/

   find wr_route where wr_lot = wolot and wr_op = op no-lock no-error.

   if not available wr_route then do:
      /* Operation does not exist */
      {pxmsg.i &MSGNUM=106 &ERRORLEVEL=3}
      next-prompt op.
      undo, retry.
   end.

   if wr_sub_cost = 0 then do:
      /* There is no subcontract cost for this operation */
      {pxmsg.i &MSGNUM=5118 &ERRORLEVEL=2}
   end.

   /*DETERMINE IF WIP ITEM OR IF COMPONENT ITEM*/
   operation_wip_mtl = no.

   if part = "" then do:
      operation_wip_mtl = yes.
      part = wr_wipmtl_part.
      display part with frame a.
   end.
   else
   if part = wr_wipmtl_part then do:
      operation_wip_mtl = yes.
   end.

   find pt_mstr where pt_part = part no-lock no-error.

   if not operation_wip_mtl and not available pt_mstr then do:
      {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
      next-prompt part with frame a.
      undo, retry.
   end.

   if not operation_wip_mtl then do:

      find wod_det where wod_lot = wo_lot and wod_op = op
                     and wod_part = part
      no-lock no-error.

      if not available wod_det then do:
         /*UNRESTRICTED COMPONENT ISSUES*/
         if clc_comp_issue or wo_type = "R" or wo_type = "E" then do:
            /* Item not on this bom */
            {pxmsg.i &MSGNUM=547 &ERRORLEVEL=2}
         end.
         /*COMPLIANCE MODULE RESTRICTS COMP ISSUE*/
         else do:
            /* Item not on this bom */
            {pxmsg.i &MSGNUM=547 &ERRORLEVEL=3}
            next-prompt part with frame a.
            undo, retry.
         end.
      end.
   end.

   /* DON'T ALLOW THIS OPERATION IF WIP  LOT  TRACING  IS
      SET  TO GO, AND EITHER THIS OR THE PREVIOUS OPERATION
      (BUT NOT BOTH) IS A NONMILESTONE OP.*/

   if is_wiplottrace_enabled()
      and is_woparent_wiplot_traced(wo_lot)
      and is_operation_lot_controlled(wo_lot, prev_operation(wo_lot, op))
      and not is_first_operation(wo_lot, op)
      and ((not is_milestone_operation(wo_lot, op)
      and   is_milestone_operation(wo_lot, prev_operation(wo_lot, op)))
      or (is_milestone_operation(wo_lot, op)
      and not is_milestone_operation(wo_lot, prev_operation(wo_lot, op))))
   then do:
      {pxmsg.i &MSGNUM=8429 &ERRORLEVEL=3}
      /*ITEM LOT TRACED BUT OP OR PREV OP NONMILESTONE*/
      undo, retry.
   end.

   display
      pt_desc1 when (available pt_mstr)
      ""      when (not available pt_mstr) @ pt_desc1
   with frame a.

   /*SET UM AND CONV*/
   if operation_wip_mtl then do:
      find pt_mstr where pt_part = part no-lock no-error.

      if not available pt_mstr then
         find pt_mstr where pt_part = wo_part no-lock.
   end.
   else do:
      find pt_mstr where pt_part = part no-lock.
   end.

   assign
      trans_um = pt_um
      trans_conv = 1.

   for first abs_mstr_item
      fields (abs_cmtindx  abs_format   abs_id     abs_item
              abs_lang     abs_line     abs_loc    abs_lotser
              abs_order    abs_par_id   abs_qty    abs_ref
              abs_shipfrom abs_shipto   abs_site   abs__qad02
              abs__qad03)
      where abs_shipfrom = abs_mstr.abs_shipfrom
        and abs_par_id   = abs_mstr.abs_id
        and abs_id       begins "i"
        and abs_order    = wolot
        and abs_line     = string(op)
        and abs_item     = part
   no-lock: end.
/*GUI*/ if global-beam-me-up then undo, leave.


   if available abs_mstr_item then do:
      if abs_mstr_item.abs__qad02 <> "" then
      assign
         trans_um   = abs_mstr_item.abs__qad02
         trans_conv = decimal(abs_mstr_item.abs__qad03).
   end. /* IF AVAILABLE abs_mstr_item THEN DO   */

   /*SET DEFAULT ISSUE LOCATION*/
   if operation_wip_mtl then do:
      /*PRIOR OP WORKCENTER FOR WIP MATERIAL*/
      default_loc = "".

      find last wr_route where wr_lot = wo_lot and wr_op < op
      no-lock no-error.
      if available wr_route then default_loc = wr_wkctr.
   end.
   else do:
      find pt_mstr where pt_part = part no-lock.
      default_loc = pt_loc.
   end.

   /*BUILD UPDATE LIST IN SR_WKFL*/
   for each sr_wkfl exclusive-lock
      where sr_userid = new_mfguser:
      delete sr_wkfl.
   end.

   assign
      i = 0
      total_lotserial_qty = 0
      v_cmmts = false.

   for each abs_mstr_item no-lock
      where abs_shipfrom = abs_mstr.abs_shipfrom
      and abs_par_id = abs_mstr.abs_id
      and abs_id begins "i"
      and abs_order = wolot
      and abs_line = string(op)
      and abs_item = part:

      create sr_wkfl.

      assign
         sr_userid = new_mfguser
         sr_site = abs_site
         sr_loc = abs_loc
         sr_lotser = abs_lotser
         sr_ref = abs_ref
         sr_qty = abs_qty
         v_cmmts = v_cmmts or abs_cmtindx <> 0
         i = i + 1
         total_lotserial_qty = total_lotserial_qty + sr_qty.

      if is_wiplottrace_enabled()
         and is_milestone_operation(wolot, op)
         and is_woparent_wiplot_traced(wolot)
         and is_operation_lot_controlled
         (wo_lot, prev_operation(wo_lot, op))
      then do:
         run create_move_wip_lot_from_abs
            in h_wiplottrace_procs
            (input abs_shipfrom, input abs_id, input trans_conv).
      end.

   end.

   default_site = abs_mstr.abs_shipfrom.
   multi_entry = no.

   if i > 1 then do:
      multi_entry = yes.

      display
         trans_um
         trans_conv
         default_site @ sr_site
         abs_mstr.abs_loc @ sr_loc
         "" @ sr_lotser
         "" @ sr_ref
         "" @ sr_qty
         multi_entry with frame a.

      /*DOES USER HAVE ACCESS TO THIS SITE*/
      access_ok = 1.
      {gprun.i ""gpsiver.p""
         "(input default_site,
           input ?,
           output access_ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.

   else
   if i = 1 then do:

      find first sr_wkfl where sr_userid = new_mfguser no-lock.

      display
         trans_um
         trans_conv
         sr_site
         sr_loc
         sr_lotser
         sr_ref
         sr_qty
         multi_entry
      with frame a.

      /*DOES USER HAVE ACCESS TO THIS SITE*/
      access_ok = 1.
      {gprun.i ""gpsiver.p""
         "(input (input sr_site),
           input ?,
           output access_ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.

   else do:

      display
         trans_um
         trans_conv
         default_site @ sr_site
         default_loc @ sr_loc
         "" @ sr_lotser
         "" @ sr_ref
         "" @ sr_qty
         multi_entry
      with frame a.

      /*DOES USER HAVE ACCESS TO THIS SITE*/
      access_ok = 1.
      {gprun.i ""gpsiver.p""
         "(input default_site,
           input ?,
           output access_ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.

   display v_cmmts with frame a.

   ststatus = stline[3].
   status input ststatus.

   if operation_wip_mtl then do:
      find pt_mstr where pt_part = part no-lock no-error.

      if not available pt_mstr then
         find pt_mstr where pt_part = wo_part no-lock.
   end.

   else do:
      find pt_mstr where pt_part = part no-lock.
   end.

   sr-loop:
   do on error undo, retry with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


      l_trans_conv = trans_conv.

      prompt-for
         sr_qty
         trans_um
         trans_conv
         sr_site         when (access_ok = 1)
         sr_loc
         sr_lotser
         sr_ref
         multi_entry     when (not operation_wip_mtl)
         v_cmmts
      editing:

         assign
            global_part = part
            global_site = input sr_site
            global_loc  = input sr_loc
            global_lot  = input sr_lotser.

         readkey.
         apply lastkey.

      end.

      if access_ok = 1 then do:
         {gprun.i ""gpsiver.p""
            "(input (input sr_site),
              input ?,
              output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if return_int = 0 then do:
            {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
            /* USER DOES NOT HAVE ACCESS TO SITE */
            next-prompt sr_site with frame a.
            undo sr-loop, retry.
         end.
      end.

      assign
         multi_entry
         cline = ""
         site = input sr_site
         location = input sr_loc
         lotserial = input sr_lotser
         lotserial_qty = input sr_qty
         v_qty = input sr_qty
         trans_um
         trans_conv
         lotref = input sr_ref
         lotserial_control = if available pt_mstr then pt_lot_ser else ""
         global_part = part
         trans_um
         trans_conv
         v_cmmts.

      if trans_conv = l_trans_conv
         and (available pt_mstr
         and trans_um <> pt_um)
      then do:

         {gprun.i ""gpumcnv.p""
            "(input trans_um,
              input pt_um,
              input pt_part,
              output trans_conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if trans_conv = ? then do:
            {pxmsg.i &MSGNUM=33 &ERRORLEVEL=2}
            trans_conv = 1.
         end.

         display trans_conv with frame a.

      end. /* IF trans_conv = l_trans_conv */

      else do:
         if available pt_mstr and trans_um = pt_um then
            trans_conv = 1.
         display trans_conv with frame a.
      end. /* ELSE DO */

      /* If specified site is not defined ship-from site, */
      /* make sure it's in the same database              */
      if site <> abs_mstr.abs_shipfrom then do:

         find si_mstr where si_site = abs_mstr.abs_shipfrom no-lock.

         ship_db = si_db.

         find si_mstr where si_site = site no-lock.

         if si_db <> ship_db then do:
            {pxmsg.i &MSGNUM=2512 &ERRORLEVEL=3}
            /*All ship-from sites must be in same db*/
            next-prompt sr_site.
            undo, retry.
         end.

      end.

      if i > 1 or multi_entry then do:

         lotnext = "".
         lotprcpt = no.

         /* ADDED SIXTH INPUT PARAMETER AS NO */
         {gprun.i ""icsrup.p""
            "(input abs_mstr.abs_shipfrom,
              input """",
              input """",
              input-output lotnext,
              input lotprcpt,
              input no)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

      else do:

         if operation_wip_mtl then do:

            /*CHECK INPUT QUEUE THIS OP*/
            {gprun.i ""rechkq.p""
               "(input wolot, input op,
                 input ""i"",
                 input lotserial_qty * trans_conv,
                 input-output msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            do for prev_wr_route:

               find last prev_wr_route
                  where prev_wr_route.wr_lot = wolot
                  and prev_wr_route.wr_op < op
               no-lock no-error.

               if available prev_wr_route
                  and prev_wr_route.wr_milestone
               then do:

                  /*CHECK OUTPUT QUEUE PREV OP*/
                  {gprun.i ""rechkq.p""
                     "(input wolot,
                       input prev_wr_route.wr_op,
                       input ""o"",
                       input - (lotserial_qty * trans_conv),
                       input-output msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.

               end.

               if available prev_wr_route
                  and not prev_wr_route.wr_milestone
               then do:

                  qty_bkfl = (lotserial_qty * trans_conv) - wr_qty_outque.

                  /*DETERMINE INPUT QUEUE OP TO CHECK; */
                  /*COULD BE PRIOR NONMILESTONES*/
                  {gprun.i ""reiqchg.p""
                     "(input prev_wr_route.wr_lot,
                       input prev_wr_route.wr_op,
                       input qty_bkfl,
                       output input_que_op_to_ck,
                       output input_que_qty_chg)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  {gprun.i ""rechkq.p""
                     "(input prev_wr_route.wr_lot,
                       input input_que_op_to_ck,
                       input ""i"",
                       input input_que_qty_chg,
                       input-output msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.

               end.

            end.

            if is_wiplottrace_enabled() and
               is_operation_queue_lot_controlled(wo_lot, op, INPUT_QUEUE)
            then do for prev_wr_route:

               for first prev_wr_route
                  where wr_lot = wolot
                    and wr_op = prev_operation(wolot, op)
               no-lock: end.

               run get_move_wip_lots_from_user in h_wiplottrace_procs
                  (input wolot,
                   input prev_operation(wolot, op),
                   input lotserial_qty,
                   input trans_conv,
                   input trans_um,
                   input wo_site,
                   input wr_wkctr,
                   input wr_mch,
                   input shipto_id,
                   input '',
                   output undo_all).

                  if undo_all then undo, retry.

            end.

         end.

         else do:

            {gprun.i ""icedit.p""
               "(input ""ISS-WO"",
                 input site,
                 input location,
                 input global_part,
                 input lotserial,
                 input lotref,
                 input lotserial_qty * trans_conv,
                 input trans_um,
                 input """",
                 input """",
                 output yn)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            if yn then undo, retry.

            if wo_site <> site
            then do:

               {gprun.i ""icedit4.p""
                  "(input ""ISS-WO"",
                    input wo_site,
                    input site,
                    input pt_loc,
                    input location,
                    input global_part,
                    input lotserial,
                    input lotref,
                    input lotserial_qty
                    * trans_conv,
                    input trans_um,
                    input """",
                    input """",
                    output yn)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               if yn then undo, retry.

            end.

         end.

         find first sr_wkfl where sr_userid = new_mfguser
            and sr_lineid = cline no-error.

         if lotserial_qty = 0 then do:
            if available sr_wkfl then do:
               total_lotserial_qty = total_lotserial_qty - sr_qty.
               delete sr_wkfl.
            end.
         end.

         else do:

            if available sr_wkfl then do:
               assign
                  total_lotserial_qty = total_lotserial_qty - sr_qty +
                                        lotserial_qty
                  sr_site = site
                  sr_loc = location
                  sr_lotser = lotserial
                  sr_ref = lotref
                  sr_qty = lotserial_qty.
            end.

            else do:
               create sr_wkfl.
               assign
                  sr_userid = new_mfguser
                  sr_lineid = cline
                  sr_site = site
                  sr_loc = location
                  sr_lotser = lotserial
                  sr_ref = lotref
                  sr_qty = lotserial_qty.
               total_lotserial_qty = total_lotserial_qty + lotserial_qty.
            end.

         end.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.


   end.

   v_cmtindx = 0.

   for first abs_mstr_item where
      abs_shipfrom = abs_mstr.abs_shipfrom and
      abs_par_id = abs_mstr.abs_id         and
      abs_id begins "i"                    and
      abs_order = wolot                    and
      abs_line = string(op)                and
      abs_item = part
   no-lock:

      /* If deleting detail line */
      if v_qty = 0 then do:

         /* Delete comments */
         for each cmt_det where cmt_indx = abs_cmtindx
         exclusive-lock:
            delete cmt_det.
         end.  /* for each cmt_det */

         /* Delete additional shipper info using form services */
         {gprun.i  ""sofsde.p""  "(recid(abs_mstr_item))" }
/*GUI*/ if global-beam-me-up then undo, leave.


      end.  /* if v_qty */

      /* Otherwise save pointer to comment */
      else v_cmtindx = abs_mstr_item.abs_cmtindx.

   end.  /* for first abs_mstr */

   {gprun.i ""reshmtb1.p""
      "(input recid(abs_mstr), input wo_lot, input op, input part,
        input trans_um, input trans_conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   for first abs_mstr_item where
      abs_shipfrom = abs_mstr.abs_shipfrom and
      abs_par_id = abs_mstr.abs_id         and
      abs_id begins "i"                     and
      abs_order = wolot                    and
      abs_line = string(op)                and
      abs_item = part
   exclusive-lock:

      /* Restore old comment index */
      abs_mstr_item.abs_cmtindx = v_cmtindx.

      /* Process comments */
      if v_cmmts then do:

         assign
            cmtindx     = abs_mstr_item.abs_cmtindx
            global_ref  = ""
            global_lang = "".

         /* Find top-level parent shipper (if any) for the line item */
         {gprun.i ""gpabspar.p""
            "(recid(abs_mstr_item), 'PS', true, output v_par_recid)" }
/*GUI*/ if global-beam-me-up then undo, leave.


         find b_abs_mstr no-lock where recid(b_abs_mstr) = v_par_recid
         no-error.

         /* Get defaults from top-level parent */
         if available b_abs_mstr then
         assign
            global_ref  = b_abs_mstr.abs_format
            global_lang = b_abs_mstr.abs_lang.

         {gprun.i ""gpcmmt01.p"" "(input 'abs_mstr')"}
/*GUI*/ if global-beam-me-up then undo, leave.

         abs_mstr_item.abs_cmtindx = cmtindx.

      end.  /* if v_cmmts */

      /* Gather additional shipper info using form services */
      {gprun.i  ""sofsgi.p""  "(recid(abs_mstr_item))" }
/*GUI*/ if global-beam-me-up then undo, leave.


   end.  /* for first abs_mstr */

   for each qad_wkfl exclusive-lock
      where qad_key1 = new_mfguser + "reshmtb.p":
      delete qad_wkfl.
   end.

end.
